---
description: "Swift documentation for 'SingleValueEncodingContainer'"
keywords: ""
root: "/v5.1"
layout: "default"
title: "SingleValueEncodingContainer"
---

<div class="intro-declaration"><code class="language-swift">protocol SingleValueEncodingContainer</code></div><p>A container that can support the storage and direct encoding of a single
non-keyed value.</p>
<div class="discussion comment"></div><h3>Instance Variables</h3><div id="codingPath-038986a6e6564f0dd444735f926a6ca4" class="declaration"><a class="toggle-link" href="#comment-codingPath-038986a6e6564f0dd444735f926a6ca4">var codingPath</a> <span class="required">Required</span><div class="comment collapse in" id="comment-codingPath-038986a6e6564f0dd444735f926a6ca4"><p>The path of coding keys taken to get to this point in encoding.</p>
<h4>Declaration</h4><code class="language-swift">var codingPath: [CodingKey]</code></div></div><h3>Instance Methods</h3><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Bool) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Bool) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: String) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: String) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Double) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Double) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Float) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Float) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Int) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Int) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Int8) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Int8) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Int16) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Int16) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Int32) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Int32) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: Int64) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: Int64) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: UInt) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: UInt) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: UInt8) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: UInt8) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: UInt16) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: UInt16) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: UInt32) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: UInt32) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: UInt64) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode(_ value: UInt64) throws</code></div></div><div id="encode-916cae29d671f40991b97828ef8e343f" class="declaration"><a class="toggle-link" href="#comment-encode-916cae29d671f40991b97828ef8e343f">func encode(_ value: T) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode-916cae29d671f40991b97828ef8e343f"><p>Encodes a single value of the given type.</p>
<ul>
<li>parameter value: The value to encode.</li>
</ul>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encode&lt;T>(_ value: T) throws where T: Encodable</code></div></div><div id="encodeNil-b0d11198b36a46b570f69fb7d0d484c4" class="declaration"><a class="toggle-link" href="#comment-encodeNil-b0d11198b36a46b570f69fb7d0d484c4">func encodeNil() throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encodeNil-b0d11198b36a46b570f69fb7d0d484c4"><p>Encodes a null value.</p>
<blockquote>
<p>Precondition:
May not be called after a previous <code>self.encode(_:)</code> call.</p>
</blockquote>
<h4>Declaration</h4><code class="language-swift">mutating func encodeNil() throws</code></div></div>